package com.fqgj.report.statistics.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.report.statistics.dao.BiAuditStatDao;
import com.fqgj.report.statistics.entity.BiAuditStatEntity;
import com.fqgj.report.statistics.entity.BiAuditStatisticEntity;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: ykpbean
 * Date: 2017-10-18
 * Time: 14:28:31.957
 */

@Repository
public class BiAuditStatDaoImpl extends AbstractBaseMapper<BiAuditStatEntity> implements BiAuditStatDao {

    @Autowired
    @Qualifier("sqlSessionFactory2")
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public List<BiAuditStatisticEntity> selectRiskAuditStatistic(String startDate, String endDate, Long eventId,
                                                                 String executorType, String version,
                                                                 String source, Integer borrowType) {
        Map<String, Object> param = new HashMap<>();
        param.put("startDate", startDate);
        param.put("endDate", endDate);
        param.put("eventId", eventId);
        param.put("executorType", executorType);
        param.put("version", version);
        param.put("source", source);
        param.put("borrowType", borrowType);
        SqlSession sqlSession = new SqlSessionTemplate(sqlSessionFactory);
        return sqlSession.selectList(getStatement(".selectRiskAuditStatistic"), param);
    }

    @Override
    public Long selectApplyCnt(String startDate, String endDate, Long eventId,
                               String executorType, String version,
                               String source, Integer borrowType, Integer resultType) {
        Map<String, Object> param = new HashMap<>();
        param.put("startDate", startDate);
        param.put("endDate", endDate);
        param.put("eventId", eventId);
        param.put("executorType", executorType);
        param.put("version", version);
        param.put("source", source);
        param.put("borrowType", borrowType);
        param.put("resultType", resultType);
        SqlSession sqlSession = new SqlSessionTemplate(sqlSessionFactory);
        List<Map<String, Object>> mapList = sqlSession.selectList(getStatement(".selectApplyCnt"), param);
        String applyCnt = "0";
        if (mapList.get(0).get("applicants") != null) {
            applyCnt = (mapList.get(0).get("applicants")).toString();
        }
        return Long.valueOf(applyCnt);
    }
}